#pragma once
#ifndef __NEZHACMEMORYREADFILE_H__
#define __NEZHACMEMORYREADFILE_H__

#include "NezhaIReadFile.h"
#include "NezhaOS.h"

namespace Nezha
{
	namespace stream
	{

	class CFile;

	class CMemoryReadFile: public IReadFile
	{
	
	typedef SharedPtr<char>::Default SharedBufferPtr;

	public:
		CMemoryReadFile();

		CMemoryReadFile(void* memory, long len, const char* fileName, bool deleteMemoryWhenDropped);

		virtual ~CMemoryReadFile();

		virtual IReadFile* clone(bool keepPos = true) const;

		void set(void* memory, long len, const char* fileName);

		bool isValid() const;

		virtual int read(void* buffer, u32 sizeToRead);

		virtual bool readAsync(void* buffer, u32 sizeToRead, Callback callback, void* arg);

		virtual bool readAsync(void* buffer, u32 sizeToRead, long finalPos, Callback callback, void* arg);

		virtual bool seek(long finalPos, bool relativeMovement = false);

		virtual long getSize() const;

		virtual long getPos() const;

		virtual const char* getFileName() const;

		virtual const char* getFullPath() const;

		virtual void* getBuffer(long* size);

		virtual bool isAllInMemory() const;

		virtual void destory();

	private:

		CFile* mFilePtr;

		void* mBuffer;
		SharedBufferPtr mSharedBuffer;
		long mLen;
		long mPos;
		String mFilename;
		};

	};
};

#endif // __NEZHACMEMORYREADFILE_H__